// Hydro submission #6406c5f8a6a35c48ca890500@1678321768154
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
int n;
scanf("%d",&n);
vector<int> a(n),b(n);
for(int&x:a) scanf("%d",&x);
for(int&x:b) scanf("%d",&x);
sort(a.begin(),a.end());
sort(b.begin(),b.end());
ll ans=0;
for(int i=0;i<n;i++)
ans+=1ll*n*(a[i]+b[i])-
2ll*a[i]*(b.end()-lower_bound(b.begin(),b.end(),a[i]))-
2ll*b[i]*(a.end()-upper_bound(a.begin(),a.end(),b[i]));
for(int i=0;i<n;i++) ans-=(n-1ll)*abs(a[i]-b[i]);
printf("%lld\n",ans);
return 0;
}
952. Largest Component Size by Common Factor | 212. Word Search II |
174. Dungeon Game | 127. Word Ladder |
123. Best Time to Buy and Sell Stock III | 85. Maximal Rectangle |
84. Largest Rectangle in Histogram | 60. Permutation Sequence |
42. Trapping Rain Water | 32. Longest Valid Parentheses |
Cutting a material | Bubble Sort |
Number of triangles | AND path in a binary tree |
Factorial equations | Removal of vertices |
Happy segments | Cyclic shifts |
Zoos | Build a graph |
Almost correct bracket sequence | Count of integers |
Differences of the permutations | Doctor's Secret |
Back to School | I am Easy |
Teddy and Tweety | Partitioning binary strings |
Special sets | Smallest chosen word |